package com.lsfb.duishangbaos.Comment;

import android.content.Context;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lsfb.duishangbaos.R;
import com.lsfb.duishangbaos.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.adapter.CommonAdapter;
import com.zgscwjm.lsfbbasetemplate.adapter.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/5/12 0012.
 */

public class CommentAdapter extends CommonAdapter<CommentBean.ListBean> {
    public CommentAdapter(Context context, int layoutId, List<CommentBean.ListBean> list) {
        super(context, layoutId, list);
    }

    @Override
    public void convert(ViewHolder holder, CommentBean.ListBean model) {
        holder.setImg(R.id.aty_homepage_img_head, URLString.IMAGES + model.getImg(), R.mipmap.img_head);
        holder.setText(R.id.aty_text_name, model.getUname());
        holder.setText(R.id.item_text_context, model.getContent());

        String[] imgs = model.getImgs().split(",");
        SimpleDraweeView img1 = holder.getView(R.id.item_img1);
        SimpleDraweeView img2 = holder.getView(R.id.item_img2);
        SimpleDraweeView img3 = holder.getView(R.id.item_img3);
        if (model.getImgs().isEmpty()) {
            holder.setViewVisible(R.id.item_img, false);
        } else {
            holder.setViewVisible(R.id.item_img, true);
            if (imgs.length == 1) {
                img1.setVisibility(View.VISIBLE);
                img2.setVisibility(View.INVISIBLE);
                img3.setVisibility(View.INVISIBLE);
                holder.setImg(R.id.item_img1, URLString.IMAGES + imgs[0], R.drawable.img_zhanwei);
            } else if (imgs.length == 2) {
                img1.setVisibility(View.VISIBLE);
                img2.setVisibility(View.VISIBLE);
                img3.setVisibility(View.INVISIBLE);

                holder.setImg(R.id.item_img1, URLString.IMAGES + imgs[0], R.drawable.img_zhanwei);
                holder.setImg(R.id.item_img2, URLString.IMAGES + imgs[1], R.drawable.img_zhanwei);

            } else if (imgs.length == 3) {
                img1.setVisibility(View.VISIBLE);
                img2.setVisibility(View.VISIBLE);
                img3.setVisibility(View.VISIBLE);

                holder.setImg(R.id.item_img1, URLString.IMAGES + imgs[0], R.drawable.img_zhanwei);
                holder.setImg(R.id.item_img2, URLString.IMAGES + imgs[1], R.drawable.img_zhanwei);
                holder.setImg(R.id.item_img3, URLString.IMAGES + imgs[2], R.drawable.img_zhanwei);
            }


        }

    }
}
